<template>
  <div class="pagination">
    <!-- 分页 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-sizes="pageSizes" :page-size.sync="pageSize" :layout="layout" :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'pagination',
  props: {
    total: {
      type: Number
    },
    pageSizes: {
      type: Array,
      default () {
        return [10, 20, 50]
      }
    },
    // 页码
    pageNum: {
      type: Number,
      default: 1
    },
    // 每页条数
    curSizes: {
      type: Number,
      default: 10
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next'
    }
  },
  computed: {
    currentPage: {
      get () {
        return this.pageNum
      },
      set (val) {
        this.$emit('update:pageNum', val)
      }
    },
    pageSize: {
      get () {
        return this.curSizes
      },
      set (val) {
        this.$emit('update:curSizes', val)
      }
    }
  },
  methods: {
    // 页数改变触发
    handleSizeChange () {
      this.$emit('getList')
    },
    // 页码改变触发
    handleCurrentChange () {
      this.$emit('getList')
    }
  }
}
</script>
